package my.learn.server.lazy.netty.tcp.advanced;

import io.netty.channel.Channel;
//import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
//import org.framework.lazy.cloud.network.heartbeat.common.advanced.tcp.server.AbstractHandleTcpReportClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
//import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
////import org.framework.lazy.cloud.network.heartbeat.server.netty.tcp.socket.NettyTcpClientPermeateServerConnectRealSocket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;
import org.springframework.stereotype.Component;
import my.learn.common.NettyProxyMsg;
import my.learn.common.advanced.tcp.server.AbstractHandleTcpReportClientTransferClientPermeateChannelInitSuccessfulTypeAdvanced;
import my.learn.common.advanced.tcp.server.AbstractHandleTcpReportClientTransferClientTypeAdvanced;
import my.learn.common.advanced.tcp.server.AbstractHandleTcpReportClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced;
import my.learn.common.constant.TcpMessageType;
import my.learn.common.enums.ChannelFlowEnum;
import my.learn.common.other.SpringContextHolder;
import my.learn.common.utils.ChannelAttributeKeyUtils;
import my.learn.server.lazy.netty.tcp.socket.NettyTcpClientPermeateServerConnectRealSocket;

/**
 * 上报客户端通信通道连接成功
 */
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Component
@Slf4j
public class ServerHandleTcpReportClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced extends AbstractHandleTcpReportClientTransferServerPermeateChannelConnectionSuccessfulTypeAdvanced<NettyProxyMsg> {
    /**
     * 处理当前数据
     *
     * @param transferChannel       当前通道
     * @param nettyProxyMsg 通道数据
     */
    @Override
    protected void doHandler(Channel transferChannel, NettyProxyMsg nettyProxyMsg) {
        // 创建目标地址连接
        byte[] msgVisitorId = nettyProxyMsg.getVisitorId();
        byte[] msgVisitorPort = nettyProxyMsg.getVisitorPort();
        byte[] msgClientTargetIp = nettyProxyMsg.getClientTargetIp();
        byte[] msgClientTargetPort = nettyProxyMsg.getClientTargetPort();
        byte[] msgClientId = nettyProxyMsg.getClientId();
        String clientId = new String(msgClientId);
        // 绑定客户端ID
        log.info("777 buildClientId");
        ChannelAttributeKeyUtils.buildClientId(transferChannel,clientId);
        ChannelAttributeKeyUtils.buildVisitorId(transferChannel,msgVisitorId);
        NettyTcpClientPermeateServerConnectRealSocket.buildNewRealServer(new String(msgVisitorId),
                Integer.parseInt(new String(msgVisitorPort)),
                new String(msgClientTargetIp),
                Integer.parseInt(new String(msgClientTargetPort)),
                transferChannel
        );


    }
}
